<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" version="-//W3C//DTD XHTML 1.1//EN" dir="ltr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Multi-service Example</title>
    <link href="css/samples.css" rel="stylesheet" type="text/css">
    <?php
        require_once("lib/jsonsscli.php");
        ini_set("error_reporting", false);
    ?>
</head>
<body><div id="page-content">

    <h1>Multi-service Example</h1>

    <h3>Service exchange log</h3>
    <pre class="console"><?php 

    JSONSSProxy::initLibrary();

    $url = "http://" . $_SERVER["SERVER_NAME"] . dirname($_SERVER["SCRIPT_NAME"]) . "/multiservice.php";
    echo "URL = " . $url . "\r\n";

    function onCreated($d) {
        echo ">>> Event Created caught by function\r\n";
        echo ">>> attached data is: " . $d . "\r\n";
    }

    try { 

        $proxy = JSONSSProxy::fromUrl($url);
        echo "Got proxy object:\r\n";
        echo "VerbService.serviceUrl = " . $proxy->VerbService->serviceUrl . "\r\n";
        echo "NounService.serviceUrl = " . $proxy->NounService->serviceUrl . "\r\n";
        echo "QuestionService.serviceUrl = " . $proxy->QuestionService->serviceUrl . "\r\n";

        $proxy->QuestionService->onCreated = "onCreated";
        echo "QuestionService.onCreated is set to function onCreated()\r\n";

        echo "Pinging QuestionService...\r\n";
        $proxy->QuestionService->ping();

        echo "Calling VerbService.Create()... ";
        $proxy->VerbService->Create();
        echo "done\r\n";

        echo "Pinging QuestionService...\r\n";
        $proxy->QuestionService->ping();

        echo "NounService.Creature is: " . $proxy->NounService->Creature . "\r\n";
        echo "Once more NounService.Creature is: " . $proxy->NounService->Creature . "\r\n";

        echo "Pinging QuestionService...\r\n";
        $proxy->QuestionService->ping();

        echo "Calling VerbService.Create() again... ";
        $proxy->VerbService->Create();
        echo "done\r\n";

        echo "Pinging QuestionService...\r\n";
        $proxy->QuestionService->ping();

        echo "Pinging QuestionService again...\r\n";
        $proxy->QuestionService->ping();

        echo "...and again...\r\n";
        $proxy->QuestionService->ping();

        echo "NounService.Creature is: " . $proxy->NounService->Creature . "\r\n";
        echo "Once more NounService.Creature is: " . $proxy->NounService->Creature . "\r\n";

        echo "Pinging QuestionService...\r\n";
        $proxy->QuestionService->ping();

    } catch (Exception $x) { 
        echo "Ooops! Exception: ". $x->getMessage() . "\r\n"; 
    } 

    try { 
        echo "Trying to set read-only NounService.Creature to \"MyCreature\"...\r\n";
        $proxy->NounService->Creature = "MyCreature";
        echo "Ooops! Succeed...\r\n"; 
    } catch (Exception $x) { 
        echo "Fine. Exception: ". $x->getMessage() . "\r\n"; 
    } 
 
    JSONSSProxy::shutdownLibrary();

    ?></pre>
</div></body>
</html>
